<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible"content="IE=8"><!--以IE8模式渲染-->
	<meta http-equiv="X-UA-Compatible"content="IE=7"><!--以IE7模式渲染-->
	<meta http-equiv="X-UA-Compatible"content="IE=9; IE=8; IE=7; IE=EDGE">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
	<title>借款新增</title>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/jquery.range.css"> 
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/long_add.css" >
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/jquery.alert.v1.2/jquery.alert.css"/>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/autocomplete/jquery.autocomplete.css" >
	<script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
	<script  type="text/javascript" src="__PUBLIC__/js/jquery.range.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/jquery.alert.v1.2/jquery.easydrag.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/jquery.alert.v1.2/jquery.alert.js"></script>

	<style type="text/css">
		.demo{width:300px; margin:0px auto 10px auto}
	</style>

	<script>
		$(function() {
			$('.single-slider').jRange({
				from: 0,
				to: 100,
				step: 10,
				scale: [0,50,100],
				format: '%s',
				width: 300,
				showLabels: true,
				showScale: true
			});
		});
	</script>
</head>
<body>
	<div class="contentPage">
		<form action="../../borrow/borrowbusiness/borrowbusiness_add" method="post" name="loanAddForm">
			<table class="addForm">
				<tr>
					<th><span>*</span>服务商：</th>
					<td>
						<input type="text" name="facilitator" id="facilitator" >
						<input type="hidden" name="facilitatorid" id="facilitatorid" >
						<span id="facilitatorSpan">必填</span>
					</td>
				</tr>
				<tr>
					<th><span>*</span>客户姓名：</th>
					<td>
						<input type= "text" name="custName" id="custName" onkeyup="querySuperior();">
						<input type= "hidden" id="refstatus" value="0" name="refstatus">
						<input type="hidden" name="custId" id="custId" >
						<span id="custNameSpan">必填</span>
					</td>
				</tr>
				<tr>
					<th><span>*</span>借款标题：</th>
					<td>
						<select id="custTitle" name="custTitle">
							<option value='0'>选择借款标题</option>
						</select>
						<span id="custRateSpan">必填</span>
					</td>
				</tr>
				<tr>
					<th><span>*</span>借款等级：</th>
					<td>
						<select name="loanlevel" id="loanlevel" onchange="setloanrate()">
							<option value='0'>选择借款等级</option>
							<?php 
								// if ($levelarr && mysqli_num_rows($levelarr)>0) 
								// {
								// 	while ($level_row = mysqli_fetch_row($levelarr)) 
								// 	{
								// 		echo "<option value='$level_row[0]'>$level_row[1]</option>";
								// 	}
								// }
							?>
						</select>
						<span id="codeSpan">必填</span>
					</td>
				</tr>
				<tr>
					<th><span>*</span>借款标准利率：</th>
					<td>
						<input type= "text" name="custRate" value="<?php echo $comm_rate; ?> "  id="custRate">%
						<span id="custRateSpan">必填</span>
					</td>
				</tr>
				<tr>
					<th><span>*</span>借款金额：</th>
					<td>
						<input type= "text" name="loanmonety" id="loanmonety">
						<span id="loanmonetySpan">必填</span>
					</td>
				</tr>
				<tr id ="percent" style="display:none;">
					<th ><span>*</span>首付百分比：</th>
					<td >
						<div class="demo">
							<input type="hidden" class="single-slider" id="percent" name="percent" value="100" />
						</div>
					</td>
				</tr>
				<tr>
					<th><span>*</span>借款期限：</th>
					<td >
						<select name="loanperiods" id="loanperiods" onchange="setvalue()">
							<option value='0'>选择借款期限</option>
							<?php 
								// if ($dateres && mysqli_num_rows($dateres)>0) 
								// {
								// 	while ($level_row = mysqli_fetch_row($dateres)) 
								// 	{
								// 		echo "<option value='$level_row[0]'>$level_row[1]</option>";
								// 	}
								// }
							?>
						</select>
						<input type="hidden" name="loanperiod" id="loanperiod">
						<span id="loanperiodsSpan">必填</span>
					</td>
				</tr>
				<tr>
					<th><span>*</span>还款方式：</th>
					<td>
						<input type="text" value="等额本息" readonly="readonly" name="code" id="code">
					</td>
				</tr>
				<tr>
					<th><span>*</span>手续费：</th>
					<td>
						<input type="text" name="loanextra"  id="loanextra">
						<span id="loanperiodsSpan">必填</span>
					</td>
				</tr>
				<tr>
					<th><span>*</span>选择审核状态：</th>
					<td>
						<select name="checkstaus" id="checkstaus" onchange="changetr()" >
							<option value='0'>选择审核状态</option>
							<?php 
								// if ($loanstatearr && mysqli_num_rows($loanstatearr)>0) 
								// {
								// 	while ($level_row = mysqli_fetch_row($loanstatearr)) 
								// 	{
								// 		echo "<option value='$level_row[0]'>$level_row[1]</option>";
								// 	}
								// }
							?>
						</selec>
						<span id="codeSpan">必填</span>
					</td>
				</tr>
				<tr id="tdfreasona">
					<td >申请未通过原因：</td>
					<td >
						<select name="freason">
							<option value='0'>选择未通过原因</option>
							<?php
								// $freasonallsql = "select f_id,f_value from bypal_borrow_freason where 1=1";
								// $freasonallres = $dbObject->execute_dql($freasonallsql);
								// if($freasonallres && mysqli_num_rows($freasonallres)>0) 
								// {
								// 	while($freasonallrow = mysqli_fetch_row($freasonallres))
								// 	{
								// 		echo "<option value='$freasonallrow[0]'>$freasonallrow[1]</option>";
								// 	}
								// }
							?>
						</select>
					</td>
				</tr>
				<tr>
					<td colspan="2" class="addButton">
						<input type="button" value="保存"  class="save" onclick="submitForm();">
						<input type="button" value="刷新"  class="clear" onclick="window.location.reload();">
					</td>
				</tr>
			</table>
		</form>
	</div>

	<script type="text/javascript" src="__PUBLIC__/js/ajax.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/autocomplete/jquery.autocomplete.min.js"></script>
	<script type="text/javascript">
function setvalue()
{
	var loanperiods = document.getElementById("loanperiods").value;
	if(loanperiods==1)
		{
		 document.getElementById("loanperiod").value=6;
		}
	if(loanperiods==2)
	{
	 document.getElementById("loanperiod").value=9;
	}
	if(loanperiods==3)
	{
	 document.getElementById("loanperiod").value=12;
	}
	if(loanperiods==4)
	{
	 document.getElementById("loanperiod").value=18;
	}
	
	}
            
            function setloanrate()
            {
                var level = document.getElementById("loanlevel").value;
                document.getElementById("custRate").value ="<?php echo $comm_rate;?>" ;
                $.get("loanpay.php",{type:"getlevel",level:level},callback);
             }
            function callback(data)
            {
		
                var custRate = document.getElementById("custRate").value;
             
            		if(data!="" && data!=null )
            	     {  
            	            var dataObj = eval("("+data+")");
            	          	var state=(dataObj.state);
            	            var mes=(dataObj.message);
            	          
            	            var ad_value=dataObj.ad_value;
            	            var all = Number(custRate)+Number(ad_value);
            	            all= parseFloat(all.toFixed(2)); 
            			if(state==1)
            			{
            				document.getElementById("custRate").value=all;
            			}
            		}
            	  
                }
function changetr()
{
	var status = document.getElementById("checkstaus").value;
	var custId = document.getElementById("custId").value;
	var facilitatorid = document.getElementById("facilitatorid").value;
	 var custName = document.loanAddForm.custName.value;
	 var facilitator   = document.loanAddForm.facilitator.value.trim();

	 
	if(status==1 || status==5|| status==4)
	{
		$("#tdfreasona").hide();
		document.getElementById("refstatus").value="1";
	
	}else if(status==2)
	{
		
		$("#tdfreasona").hide();
		 if(custName==false){
	          jAlert("请填写用户姓名","错误提示");
	          return false;
	      }
		  else if(facilitator==false){
	  	     jAlert("商户不能为空","错误提示");
	         return false;
	     }else{
		  $.get("loanpay.php",{type:"getcheck",custId:custId,facilitatorid:facilitatorid},callback2);
	     }
	}
	else
		{
		$("#tdfreasona").show(); 
		document.getElementById("refstatus").value="1";
		}

}
function callback2(data)
{
	if(data!="" && data!=null )
     {  
            var dataObj = eval("("+data+")");
          	var state=(dataObj.state);
            var mes=(dataObj.message);
        	
		if(state==1)
		{
			document.getElementById("refstatus").value="1";
			jAlert(mes,"审核提示");
	         
		}else
		{
			document.getElementById("refstatus").value="0";
			 jAlert(mes,"错误提示");
	         return false;
		}	
	}
}             
    function submitForm(){

       var custName = document.loanAddForm.custName.value;
       var loanmonety= document.loanAddForm.loanmonety.value.trim();
       var loanperiods   = document.loanAddForm.loanperiods.value;
       var facilitator   = document.loanAddForm.facilitator.value.trim();
       var custTitle = document.loanAddForm.custTitle.value.trim();
       var refstatus = document.loanAddForm.refstatus.value.trim();
       
       if(custName==false){
           jAlert("请填写用户姓名","错误提示");
           return false;
       }
       if(custTitle==0)
           {
    	   jAlert("请填写借款标题","错误提示");
           return false;
           }
       if(loanmonety==false || isNaN(loanmonety)){
    	   jAlert("借款金额不能为空且必须为数字","错误提示");
           return false;
       }
       if(loanperiods==false || isNaN(loanperiods)){
    	   jAlert("借款期限不能为空且必须为数字","错误提示");
           return false;
       }
       if(facilitator==false){
    	   jAlert("商户不能为空","错误提示");
           return false;
       }
       if(refstatus==0)
           {
    	   jAlert("商户或客户认证材料未通过","审核提示");
   		return false;
           }
           
      else {
        	document.loanAddForm.submit();
       }

    }
    $().ready(function (){

 	   $.ax("loan_query.php",{method:"querycustName"}, null,"POST","json",function (data){

 		    if(data!=null){
 			   autoComplete(data);  
 		    }else {
 		       alert('系统中不存在任何用户');
 			}

 	   },function(e){alert('访问服务器文件失败');});

    });      

    $().ready(function (){

  	   $.ax("loan_query.php",{method:"queryfacilitator"}, null,"POST","json",function (data){

  		    if(data!=null){
  			   autoCompletef(data);  
  		    }else {
  		       alert('系统中不存在任何商家');
  			}

  	   },function(e){alert('访问服务器文件失败');});

     });       
    function autoCompletef(emails){
        
  	   $('#facilitator').focus().autocomplete(emails, {
             max: 12,    //列表里的条目数
             minChars: 0,    //自动完成激活之前填入的最小字符
             width: 168,     //提示的宽度，溢出隐藏
             scrollHeight: 300,   //提示的高度，溢出显示滚动条
             matchContains: true,    //包含匹配，就是data参数里的数据，是否只要包含文本框里的数据就显示
             autoFill: false,    //自动填充
             formatItem: function(row, i, max) {
                    //return i + '/' + max + ':"' + row.name + '"[' + row.to + ']';
                      return row.name;
             },
             formatMatch: function(row, i, max) {
                      return row.name;
                    //return row.name;
             },
             formatResult: function(row) {
                      return row.name;
             }
          }).result(function(event, row, formatted) {
                    $('#facilitatorid').val(row.id);
                    queryfactype();
                    
          });
  	   
     }       

    function queryfactype()
    {
		var facilitatorid = document.getElementById("facilitatorid").value;
		
		$.get("loanpay.php",{type:"getcheckfac",facilitatorid:facilitatorid},callbackfac);
		   


    }

    function callbackfac(seldata)
    {
       
    	if(seldata!="" && seldata!=null )
        {  
               var dataObj = eval("("+seldata+")");
               var state=(dataObj.state);
               var mes=(dataObj.message);
             
           	   var selectarr = dataObj.data;
           	  
           	$("#custTitle").html(""); 
            $('#custTitle').attr("length",'0'); 
            var a = document.getElementById('custTitle');
            
           	for(var i=0;i<selectarr.length;i++){
           		
           	a.options.add(new Option(selectarr[i].borrow_tiname,selectarr[i].borrow_tiname)); 
           	}
           	   
   		if(state==1)
   		{
   			
   		
   	   		document.getElementById("percent").style.display="none";
   			
   	         
   		}else
   		{
   			document.getElementById("percent").style.display="none";
   			
   		}	
   	}

    }
    function autoComplete(emails){
        
 	   $('#custName').focus().autocomplete(emails, {
            max: 12,    //列表里的条目数
            minChars: 0,    //自动完成激活之前填入的最小字符
            width: 168,     //提示的宽度，溢出隐藏
            scrollHeight: 300,   //提示的高度，溢出显示滚动条
            matchContains: true,    //包含匹配，就是data参数里的数据，是否只要包含文本框里的数据就显示
            autoFill: false,    //自动填充
            formatItem: function(row, i, max) {
                   //return i + '/' + max + ':"' + row.name + '"[' + row.to + ']';
                     return row.name;
            },
            formatMatch: function(row, i, max) {
                     return row.name;
                   //return row.name;
            },
            formatResult: function(row) {
                     return row.name;
            }
         }).result(function(event, row, formatted) {
                   $('#custId').val(row.id);
               

         });
 	   
    }    
                                      
   //#js trim(）方法在IE7，8不支持
   String.prototype.trim = function () {
   	   return this .replace(/^\s\s*/, '' ).replace(/\s\s*$/, '' );
   }     
</script>
</body>
</html>
